﻿// See https://aka.ms/new-console-template for more information
using System.Text;
using System.Text.Json;
using XSystem.Security.Cryptography;

using (var httpclient = new HttpClient())
{
    var timespan= new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
    string url = "http://tcm.api.boyli.net/api/Dock/SavePatientInfo";
    RequestModel request = new();
    request.DockSerNumber = "20211215";
    request.StudioId = 14144;
    request.DoctorId = "zwy01";
    request.Name = "苗东川";
    request.Gender = 1;
    request.Age = "56";
    request.Text = "sssss";
    request.TCMConstitution = "ceshi";
    request.Signature = GetMD5_X2(request.DockSerNumber + "," + request.DoctorId + "," + request.StudioId + "," + timespan + "," + "58ACDEA4-3766-47A7-AEB5-1A61B6BCA10B");
    var requestJson = JsonSerializer.Serialize(request);
    var response =await httpclient.PostAsync(url, new StringContent(requestJson, System.Text.Encoding.UTF8, "application/json"));
    var result = await response.Content.ReadAsStringAsync();
    Console.WriteLine(result);
}


string GetMD5_X2(string Password)
{
    MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
    byte[] bytValue, bytHash;
    bytValue = System.Text.Encoding.UTF8.GetBytes(Password);
    bytHash = md5.ComputeHash(bytValue);
    md5.Clear();
    StringBuilder sTemp = new StringBuilder(Password.Length);
    for (int i = 0; i < bytHash.Length; i++)
    {
        sTemp.Append(bytHash[i].ToString("x2"));

        //加密结果"x"结果为32位,"x3"结果为48位,"x4"结果为64位
    }
    return sTemp.ToString();
}

internal class RequestModel
{
    public string DockSerNumber { get; set; }
    public int StudioId { get; set; }
    public string Signature { get; set; }
    public string DoctorId { get; set; }
    public string Name { get; set; }
    public int Gender { get; set; }
    public string Age { get; set; }
    public string Text { get; set; }
    public string TCMConstitution { get; set; } 
}